﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SMP_QuanLySV.BLL;

namespace SMP_QuanLySV.Presentation
{
    public partial class frmLogin : Form
    {

        BLLUserManager usm;

        public frmLogin()
        {
            InitializeComponent();
            // my code
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            usm = new BLLUserManager();
            if (usm.checkValid(txtUsername.Text, txtPassword.Text) == true)
            {
                UIManager.currentUserName = txtUsername.Text;
                UIManager.currentUserPass = txtPassword.Text;

                txtUsername.Text = "";
                txtPassword.Text = "";

                UIManager.switchToMainForm();
            }
            else
                MessageBox.Show("Bạn nhập sai username và password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            txtUsername.Text = "";
            txtPassword.Text = "";
        }

        private void frmLogin_Shown(object sender, EventArgs e)
        {
            txtUsername.Text = "";
            txtPassword.Text = "";
        }

        private void frmLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
